package com.hfuuTaf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hfuuTaf.mapper.*;
import com.hfuuTaf.pojo.*;
import com.hfuuTaf.service.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/***
 * 俱乐部的主页
 */
@Controller
public class tafMainController {
    //可以直接使用mybatis-plus, 但是不推荐,根据阿里巴巴代码规范,建议使用Service层
    private final homePromoteService homePromoteService;
    private final mainContentService mainContentService;
    private final membersService membersService;
    private final photosService photosService;
    private final trainProgramService trainProgramService;
    private final welfareService welfareService;
    //下面则是直接使用mybatis-plus
    private final homePromoteMapper homePromoteMapper;
    private final mainContentMapper mainContentMapper;
    private final membersMapper membersMapper;
    private final promotionalPhotosMapper promotionalPhotosMapper;
    private final trainProgramMapper trainProgramMapper;
    private final welfareMapper welfareMapper;

    public tafMainController(
            homePromoteService homePromoteService,
            mainContentService mainContentService,
            membersService membersService,
            photosService photosService,
            trainProgramService trainProgramService,
            welfareService welfareService,
            //上面是走service层,下面直接是plus插件
            homePromoteMapper homePromoteMapper,
            mainContentMapper mainContentMapper,
            membersMapper membersMapper,
            promotionalPhotosMapper promotionalPhotosMapper,
            trainProgramMapper trainProgramMapper,
            welfareMapper welfareMapper,
            yearMemberMapper yearMemberMapper
    ) {
        this.homePromoteService = homePromoteService;
        this.mainContentService = mainContentService;
        this.membersService = membersService;
        this.photosService = photosService;
        this.trainProgramService = trainProgramService;
        this.welfareService = welfareService;
        this.homePromoteMapper = homePromoteMapper;
        this.mainContentMapper = mainContentMapper;
        this.membersMapper = membersMapper;
        this.promotionalPhotosMapper = promotionalPhotosMapper;
        this.trainProgramMapper = trainProgramMapper;
        this.welfareMapper = welfareMapper;
    }

    @RequestMapping(value = {"/", "/index"})
    public String index(Model model) {
        // 简单介绍, 大屏幕下面三个小介绍
        List<homePromote> homePromote = homePromoteService.queryAll();
        model.addAttribute("homePromote", homePromote);
        //主页面所有的单数据,可直接使用的数据集
        mainContent mainContent = mainContentService.queryList();
        model.addAttribute("mainContent", mainContent);
        //三个训练标题
        QueryWrapper<trainProgram> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id").last("limit 3");
        List<trainProgram> trainPrograms = trainProgramMapper.selectList(wrapper);
        model.addAttribute("trainPrograms",trainPrograms);
        //福利好处
        List<welfare> welfare = welfareService.queryAll();
        model.addAttribute("welfare",welfare);
        //俱乐部宣传照片
        QueryWrapper<promotionalPhotos> photosQueryWrapper = new QueryWrapper<>();
        photosQueryWrapper.orderByDesc("id");
        List<promotionalPhotos> promotionalPhotos = promotionalPhotosMapper.selectList(photosQueryWrapper);
        model.addAttribute("promotionalPhotos",promotionalPhotos);
        //俱乐部管理层
        QueryWrapper<members> membersWar= new QueryWrapper<>();
        membersWar
                .or().eq("vip",4)
                .or().eq("vip",5)
                .or().eq("vip",6);
        List<members> members = membersMapper.selectList(membersWar);
        model.addAttribute("members",members);
        //俱乐部明星
        QueryWrapper<members> membersVip= new QueryWrapper<>();
        membersVip.eq("vip",0);
        List<members> yearMembers = membersMapper.selectList(membersVip);
        model.addAttribute("yearMembers",yearMembers);
        return "index";
    }
    /**
     * 怎么训练?长短慢*/
    @RequestMapping( "/activity")
    public String activity(Model model){
        List<trainProgram> trainPrograms = trainProgramService.queryAll();
        model.addAttribute("trainPrograms",trainPrograms);
        return "activity";
    }
    @RequestMapping( "/star")
    public String star(Model model){
        QueryWrapper<members> wrapper = new QueryWrapper<>();
        wrapper.eq("vip",0)
                .or().eq("vip",4)
                .or().eq("vip",5)
                .or().eq("vip",6);
        List<members> star = membersMapper.selectList(wrapper);
        model.addAttribute("star",star);
        //俱乐部领导团队
        QueryWrapper<members> wrapper2 = new QueryWrapper<>();
        wrapper2.eq("vip",1).or().eq("vip",3).or().eq("vip",4).or().eq("vip",6);//3是 管理层和教练都有
        List<members> mbo = membersMapper.selectList(wrapper2);
        model.addAttribute("mbo",mbo);
        //俱乐部教练
        QueryWrapper<members> wrapper3 = new QueryWrapper<>();
        wrapper3.eq("vip",2).or().eq("vip",3).or().eq("vip",5).or().eq("vip",6);//3是 管理层和教练都有
        List<members> coach = membersMapper.selectList(wrapper3);
        model.addAttribute("coach",coach);
        return "star";
    }
    @RequestMapping( "/welfare")
    public String welfare(Model model){
        //福利好处
        List<welfare> welfare = welfareService.queryAll();
        model.addAttribute("welfare",welfare);
        return "welfare";
    }

    @RequestMapping( "/addSuccess")
    public String addSuccess(){
        return "addSuccess";
    }
    @RequestMapping( "/addFail")
    public String addFail(){
        return "addSuccess";
    }
}
